<script>
    jxt.div.newJson = function (dataJson) {
        if (!dataJson) dataJson = jxt.div.dataJson;
        var _text = jxt.text.newJson();
        var _self = jxt.tag.newJson(dataJson);
        _self.children = [];

        _self.children.push(_text.id);
        return [_self, _text];
    };



    jxt.div.text_editend = function (eleid) {
        var jxtid = eleid;
        if (!jxtid) {
            alert("iderr:" + jxtid);
            return;
        }
        var node = jxt.getnode(jxtid);
        if (!node) {
            alert("err:" + jxtid);
            return;
        }
        var ele = $("#" + jxtid);
        var _html = $.trim($(ele).html());
        if (node.content == _html) return;
        var _txt = $.trim($(ele).text());
        if (node.content != _txt) {
            node.content = _txt;
        }

        jxt.msg.radio(eleid, "nodechange");
        jxt.render(jxt.nowlevoneid, true);

    };

    jxt.div.add = function (eleid, tagname, attrs) {

        var _eleid = eleid;
        var n = jxt.getnode(_eleid);
        var newn = jxt.newJson(tagname, attrs);
        var _eid = jxt.tag.getNowEditEle(eleid); // $("#" + eleid).attr("noweditid");
        jxt.tag.add(n, newn, _eid);
        jxt.addNode(newn);
        jxt.msg.radio(eleid, "nodechange");
        jxt.render(eleid, true);
    };
    jxt.div.help_callback= jxt.div._add_ = function (subscribe_id, eventkey, attrs, event_source_id) {

        switch (eventkey){
            case "help_img":
                jxt.div.add(subscribe_id, "img", attrs);
                break;
            case "help_file":
                jxt.div.add(subscribe_id, "file", attrs);
                break;
            case "help_link":
                jxt.div.add(subscribe_id, "link", attrs);
                break;
        }

    };
    /* jxt.div.format = function(node) {
     if (!_txt) {
     var id = jxt.getLevOneEleID(eleid);
     var node = jxt.getnode(id);
     node.splice($.inArray(eleid, ary), 1);
     }
     };*/
    jxt.div.render = function (eleid, edit) {
        if (!edit) {
            jxt.tag.render(eleid, edit);
            return;
        }
        jxt.tag.render(eleid, edit, true);
        var children = jxt.children(eleid);
        if (children) {
            for (var i = 0; i < children.length; i++) {
                var n = jxt.getnode(children[i]);
                if (n.type == 'text') {
                    jxt.tag.render(n, edit, true, 'jhm_div_text_edit');

                } else {
                    jxt.tag.render(n, edit, true);
                }

            }
        }

    };



    jxt.div.create = function (subscribe_id, eventkey, attrs, event_source_id) {
        var node = jxt.div.newJson();
        if(attrs && attrs.tpname)
        {
            node[0].tpname=attrs.tpname;
        }
        jxt.msg.radio("div", "addmainnode", {"newnodelist": node});
        //jxt.div.render(node[0].id);
       //jxt.route.getFunc('div.editbegin')(node[0].id);
        jxt.route.exe('div.editbegin',null,node[0].id)

    };
    jxt.msg.subscribe("div", "creatediv", jxt.div.create);



</script>